//
//  OMPropertyTrackByTableCell.m
//  OMENGO
//
//  Created by 梁尚嘉 on 2016/12/15.
//  Copyright © 2016年 Kamfat. All rights reserved.
//

#import "OMPropertyTrackByTableCell.h"
#import "OMDeliveryInfo.h"
@interface OMPropertyTrackByTableCell ()



@end

@implementation OMPropertyTrackByTableCell

- (void)configure
{
    [super configure];
    _containView = [UIView new];
    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    [self.contentView addSubview:_containView];
    [_containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
    
    [self.containView addSubview:self.nameLabel];
    [self.containView addSubview:self.phoneLabel];
    [self.containView addSubview:self.addressLabel];
    [self.containView addSubview:self.isDefaultLabel];

    self.backgroundColor = SM_whiteColor;
    self.contentView.backgroundColor = [UIColor clearColor];
    self.canHighLight = YES;
    self.nameLabel.text = @"姓名";
    self.phoneLabel.text = @"133********";
    self.addressLabel.text = @"地址";



    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(SM_SIZE(30)));
        make.top.equalTo(@(SM_SIZE(30)));
        make.right.equalTo(@(SM_SIZE(-30)));
    }];

    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.addressLabel.mas_left);
        make.top.equalTo(self.addressLabel.mas_bottom).offset(SM_SIZE(15));
    }];

    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel.mas_centerY);
        make.left.equalTo(self.nameLabel.mas_right).offset(SM_SIZE(10));
    }];

    [self.isDefaultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.phoneLabel.mas_right).offset(SM_SIZE(20));
        make.centerY.equalTo(self.phoneLabel.mas_centerY);
        make.width.equalTo(@(SM_SIZE(60)));
        make.height.equalTo(@(SM_SIZE(30)));
    }];


}

- (void)configureCellWithObj:(OMDeliveryInfo *)info
{
    self.nameLabel.text = info.consignee?info.consignee:@"请添加或选择收货地址";
    if (![Storage isLogin]) {
        self.nameLabel.text = [self.nameLabel.text stringByAppendingString:@" (您当前未登录)"];
    }
    self.phoneLabel.text = info.phone;
    self.addressLabel.text = !info?nil:[NSString stringWithFormat:@"%@ %@",info.areaName,info.address];
    self.isDefaultLabel.hidden = !info.isDefault;
}

#pragma mark - Getters


- (UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.textColor = HEXCOLOR(@"#656565");
        _nameLabel.font = SM_CFont(26);
        _nameLabel.numberOfLines = 2;
    }
    return _nameLabel;
}

- (UILabel *)phoneLabel
{
    if (!_phoneLabel) {
        _phoneLabel = [UILabel new];
        _phoneLabel.textColor = HEXCOLOR(@"#656565");
        _phoneLabel.font = SM_CFont(26);
        _phoneLabel.font = self.nameLabel.font;
    }
    return _phoneLabel;
}

- (UILabel *)addressLabel
{
    if (!_addressLabel) {
        _addressLabel = [UILabel new];
        _addressLabel.font = SM_CFont(30);
        _addressLabel.textColor = SM_blackColor;
    }
    return _addressLabel;
}

- (UILabel *)isDefaultLabel
{
    if (!_isDefaultLabel) {
        _isDefaultLabel = [UILabel new];
        _isDefaultLabel.font = SM_CFont(23);
        _isDefaultLabel.textColor = SM_whiteColor;
        _isDefaultLabel.text = @"默认";
        _isDefaultLabel.layer.cornerRadius = SM_SIZE(3);
        _isDefaultLabel.layer.borderWidth = 1.f;
        _isDefaultLabel.clipsToBounds = YES;
        _isDefaultLabel.layer.borderColor = SM_thumeColor.CGColor;
        _isDefaultLabel.textColor = SM_thumeColor;
        _isDefaultLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _isDefaultLabel;
}

+ (CGFloat)cellHeight
{
    return SM_SIZE(150);
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    if (self.canHighLight) {
        self.backgroundColor = highlighted ? HEXCOLOR(@"F6F6F6") : SM_whiteColor;
    }
}

@end
